package msr.frontend;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import msr.object.Yoyaku;
import msr.service.OracleService;
import msr.util.DateParse;
import msr.util.Define;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterController extends ActionSupport {

	/**
	 * 
	 */
	OracleService oService = new OracleService();
	Yoyaku yoyakuObj = new Yoyaku();
	private String productcode;
	private String productname;
	private String productcapacity;
	private String productweight;
	private String productexpect_year;
	private String productquantity;
	private String productexpect_month;
	private String productexpect_day;
	private String productbreakout;
	private String productcomment;
	private String productgetcd;
	private String farmcd;
	private String prefcd;
	private String jichikucd;
	private String actionType;
	private static final long serialVersionUID = 1L;

	public String execute() {
		Map<String, Object> rtData = new HashMap<String, Object>();
		// add data into map
		System.out.println("value of name " + productname);
		System.out.println("value of code " + productcode);
		System.out.println("value of action type " + actionType);

		String productdate = new DateParse().parseDate(productexpect_year,
				productexpect_month, productexpect_day);
		System.out.println("value of productdate " + productdate);
		rtData.put("productcode", productcode);
		rtData.put("productcapacity", productcapacity);
		rtData.put("productexpectdate", productdate);
		System.out.println("value of action type " + actionType);
		// if (actionType.equals(RequestAction.HISTORY_REGISTER)) {
		// System.out.println("history register");
		// } else if (actionType.equals(RequestAction.SEARCH_REGISTER)) {
		// System.out.println("search register");
		// } else {
		// System.out.println("other register");
		// }
		rtData.put("productquantity", productquantity);
		rtData.put("productbreakout", productbreakout);
		rtData.put("productcomment", productcomment);
		rtData.put("productgetcd", productgetcd);
		rtData.put("productweight", productweight);
		rtData.put("farmcd", farmcd);
		rtData.put("prefcd", prefcd);
		rtData.put("jichikucd", jichikucd);
		// get date now
		java.util.Date utilDate = new java.util.Date();
		java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
		System.out.println("value of sqlDate " + sqlDate);
		rtData.put("ins_time", sqlDate);
		rtData.put("up_time", sqlDate);
		rtData.put("productshoriflag", Define.UNRESOLVE);// 未処理
		rtData.put("kubun_fa_yoyaku", Define.NEW);
		rtData.put("feedName", productname);
		rtData.put("formName", Define.UNDEFINED);
		boolean check = false;
		try {
			check = oService.addBooking(rtData);
		} catch (SQLException e) {
			e.printStackTrace();
			return ERROR;
		}
		if (!check) {
			addActionError(getText("error.inserterror"));
			return ERROR;
		} else
			return SUCCESS;
	}

	public String getProductweight() {
		return productweight;
	}

	public void setProductweight(String productweight) {
		this.productweight = productweight;
	}

	public String getProductcode() {
		return productcode;
	}

	public void setProductcode(String productcode) {
		this.productcode = productcode;
	}

	public String getProductname() {
		return productname;
	}

	public void setProductname(String productname) {
		this.productname = productname;
	}

	public String getProductcapacity() {
		return productcapacity;
	}

	public void setProductcapacity(String productcapacity) {
		this.productcapacity = productcapacity;
	}

	public String getProductexpect_year() {
		return productexpect_year;
	}

	public void setProductexpect_year(String productexpect_year) {
		this.productexpect_year = productexpect_year;
	}

	public String getProductquantity() {
		return productquantity;
	}

	public void setProductquantity(String productquantity) {
		this.productquantity = productquantity;
	}

	public String getProductexpect_month() {
		return productexpect_month;
	}

	public void setProductexpect_month(String productexpect_month) {
		this.productexpect_month = productexpect_month;
	}

	public String getProductexpect_day() {
		return productexpect_day;
	}

	public void setProductexpect_day(String productexpect_day) {
		this.productexpect_day = productexpect_day;
	}

	public String getProductbreakout() {
		return productbreakout;
	}

	public void setProductbreakout(String productbreakout) {
		this.productbreakout = productbreakout;
	}

	public String getProductcomment() {
		return productcomment;
	}

	public void setProductcomment(String productcomment) {
		this.productcomment = productcomment;
	}

	public Yoyaku getYoyakuObj() {
		return yoyakuObj;
	}

	public void setYoyakuObj(Yoyaku yoyakuObj) {
		this.yoyakuObj = yoyakuObj;
	}

	public String getProductgetcd() {
		return productgetcd;
	}

	public void setProductgetcd(String productgetcd) {
		this.productgetcd = productgetcd;
	}

	public String getFarmcd() {
		return farmcd;
	}

	public void setFarmcd(String farmcd) {
		this.farmcd = farmcd;
	}

	public String getPrefcd() {
		return prefcd;
	}

	public void setPrefcd(String prefcd) {
		this.prefcd = prefcd;
	}

	public String getJichikucd() {
		return jichikucd;
	}

	public void setJichikucd(String jichikucd) {
		this.jichikucd = jichikucd;
	}

	public String getActionType() {
		return actionType;
	}

	public void setActionType(String actionType) {
		this.actionType = actionType;
	}

}
